require_relative '../create-snapshot.rb'

describe "Creating a Snapshot" do

  before(:each) do
    @api = RightAPI.new
    @snapshot = EBSSnapshot.new 300, @api
    @volume_id = 773499
  end
  
  it "should get snapshot info back" do
    mock(@api).headers.twice {{
        :location => "url/snap_123",
        :status => "201"
    }}
    mock(@snapshot).send_create_snapshot("nick", "desc", @volume_id) { nil }
    mock(@snapshot).sleep_until_completed("snap_123") { nil }
    @snapshot.create_snapshot("nick", "desc", @volume_id).should == "snap_123"
  end

  
  it "should fail if request fails" do
    mock(@api).headers {{
        :status => "400"
    }}
    mock(@snapshot).send_create_snapshot("nick", "desc", @volume_id) {nil}

    expect { @snapshot.create_snapshot("nick", "desc", @volume_id) }.to raise_error
  end
  
end